package com.cy.pj.module.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.List;
@Controller
public class ModelAndController {

    @RequestMapping("/doModeAndView01")
    public String doModeAndView(Model model){
        model.addAttribute("name","jason");
        model.addAttribute("state","ok");
        return "view";
    }

    @RequestMapping("/doModeAndView02")
    public ModelAndView doModelAndView(ModelAndView mv){
        mv.addObject("name","lalala");
        mv.addObject("state","ok111");
        mv.setViewName("view");
        return mv;
    }//这里的ModelAndView对象是Model对象和View对象的合体

    @RequestMapping("/doModeAndView03")
    public ModelAndView doModelAndView03(ModelAndView mv){
        List<String> list = new ArrayList<>();
        list.add("北京");
        list.add("上海");
        list.add("深圳");
        mv.addObject("citys",list);
        mv.setViewName("view");
        return mv;
    }

}
